package models;

import java.util.*;
import models.mappers.*;
import voidlib.*;

/**
 *
 * @author nevidimov
 */
public class Clan extends VoidModel {
    protected VoidMapper mapper = new ClanMapper();
    
    @Override
    public VoidMapper getMapper() {
        return mapper;
    }
    
    @Override
    protected String _getModelId() {
        return "id";
    }    
    
    public int _id = -1;
    public int _ownerId;
    public String _title;
    
    public Clan() {
    }
    
    public Clan(int ownerId, String title) {
        this._ownerId = ownerId;
        this._title = title;
    }
    
    public int getOwnerId() {
        return _ownerId;
    }
    
    public String getTitle() {
        return _title;
    }
    
    public int getId() {
        return _id;
    }
    
    public User getOwner() {
        return new User().getMapper().fetch(getOwnerId());
    }
    
    public boolean remove() {
        List<Bandit> bandits = getBandits();
        for (Bandit bandit : bandits) {
            bandit.leaveClan();
        }
        VoidMapper mapper = getMapper();
        mapper.delete(mapper.getId() + " = ?", getId());
        return true;
    }
    
    public List<Bandit> getBandits() {
        return new Bandit().getMapper().fetchAll("clan_id = ?", getId());
    }
}


